#ifndef ELASTICSEARCH_CLIENT_H
#define ELASTICSEARCH_CLIENT_H

#include <string>
#include <list>
#include <optional>
#include "ESCells.h"
#include "util.h"

class ElasticsearchClient
{
public:
    ElasticsearchClient(std::string ip, int port);
    ~ElasticsearchClient();

    std::string GetErrorString();

public:
    bool Ok();
    Status CreateIndex(const std::string& indexName);
    Status DeleteIndex(const std::string& indexName);

    Status CreateDocument(const std::string& indexName, const std::string& rowKey, const std::string& column, const std::string& value, bool canDivide = false);
    Status CreateDocument(const std::string& indexName, const std::string& rowKey, std::list<std::tuple<std::string, std::string, bool>> cells);
    Status CreateDocument(const std::string& indexName, const ESCells& rows);
    Status DeleteDocument(const std::string& indexName, const std::string& rowKey, const std::string& column);
    Status DeleteDocument(const std::string& indexName, const std::string& rowKey);

    // the first string is row_key, the second string is column, the 3rd string is value.
    std::optional<std::list<std::tuple<std::string, std::string, std::string>>> SearchInIndex(const std::string& indexName, const std::string &keywords, size_t from = 0, size_t size = 0);

private:
    std::string ip;
    int port;
    std::string errorString;
};


#endif //ELASTICSEARCH_CLIENT_H
